<?php

namespace app\common\model;

use think\Cache;

/**
 * 骰子-》撒比恩象征 模型类
 * Class DivinationTips
 * @package app\common\model
 */
class DivinationSabienTips extends Base
{
    protected $table = 'wechat_backup_07_18_14_43_00.app_sabien';// 定义表名

    /** 获取详情
     * @param array $map
     * @return array|bool|false|mixed|\PDOStatement|string|\think\Model
     */
    public function getDetail($map)
    {
        $key = $map['sign'] . '-' . floor($map['deg']);
        $result = false;
        if ($this->cache_on >= 1) {
            $result = Cache::get('sabien_' . $key);
        }
        if ($result === false) {
            try {
                $result = $this->field('text')
                    ->where('sign_deg', $key)
                    ->find();
            } catch (\Exception $e) {
                // 错误信息写入日志
                \think\Log::write('获取骰子词条错误:' . '[' . $key . ']', 'error', true);
            }
            $result = json_decode(json_encode($result, true), true);

            if ($this->cache_on >= 1) {
                Cache::set('sabien_' . $key, $result, 86400 * 7);
            }
        }

        return $result;
    }
}
